from PyQt5.QtWidgets import ( QHBoxLayout, QLabel, QPushButton,QDoubleSpinBox)
from components.actiondialog import ActionDialog


class DelayDialog(ActionDialog):
    def __init__(self, action=None, parent=None):
        super().__init__(parent)

        self.action = action if action else {"type": "delay", "seconds": 1}

        # 延时时间
        delay_layout = QHBoxLayout()
        delay_layout.addWidget(QLabel("延时时间(秒):"))
        self.delay_spin = QDoubleSpinBox()
        self.delay_spin.setRange(0, 3600)
        self.delay_spin.setValue(self.action.get("seconds", 1))
        delay_layout.addWidget(self.delay_spin)

        # 按钮
        button = QPushButton("确定")
        button.clicked.connect(self.accept)

        self.layout.addLayout(delay_layout)
        self.layout.addWidget(button)

    def accept(self):
        self.action = {
            "type": "delay",
            "seconds": self.delay_spin.value(),
            "desc": f"延时 {self.delay_spin.value()} 秒"
        }
        super().accept()
